package wh.coach._ser;

import java.time.Duration;

/**
 * @author hangwen
 * @date 2023/7/17
 */
public class Profiler {

    public static void profile(String task, Runnable action, int repeats) {
        final long start = System.currentTimeMillis();

        for (int i = 0; i < repeats; i++) {
            action.run();
        }

        long cost = System.currentTimeMillis() - start;
        System.out.printf("task [%s] repeat [%s] times,cost:[%s]%n", task, repeats, Duration.ofMillis(cost));

    }
}
